package cn.nfwx.tv.fragment.dialog;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import cn.nfwx.tv.R;

/**
 * Created by dell on 2018/1/19.
 */

public class WifiDialogFragment extends CommonDialogFragment {
    protected static final String EXTRA_NAME_CANCELABLE = "cancelable";
    protected TextView mTitleTv;
    protected TextView mMessageTv;
    protected Button mConfirm;
    protected RelativeLayout rl_wifi;
    protected LinearLayout ll_wifi;
    private View.OnClickListener mPositiveListener;


    public static WifiDialogFragment newInstance(boolean cancelable) {
        WifiDialogFragment instance = new WifiDialogFragment();
        Bundle bundle = new Bundle();
        bundle.putBoolean(EXTRA_NAME_CANCELABLE, cancelable);
        instance.setArguments(bundle);
        return instance;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_wifi;
    }

    /**
     * 是否填满整个屏幕
     */
    protected boolean isMatchParent() {
        return true;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        rl_wifi = findView(R.id.rl_wifi);
        ll_wifi = findView(R.id.ll_wifi);
        mTitleTv = findView(R.id.confirm_tv_title);
        mMessageTv = findView(R.id.confirm_tv_message);
        mConfirm = findView(R.id.confirm_btn_positive);
        init();
    }

    private void init() {
        //是否允许关闭
        boolean cancelable = getArguments().getBoolean(EXTRA_NAME_CANCELABLE, true);
        setCancelable(cancelable);
        ll_wifi.setClickable(true);
        mConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mPositiveListener != null) {
                    mPositiveListener.onClick(v);
                }
            }
        });

    }

    @Override
    protected boolean isOutsideTouchable() {
        return true;
    }

    public void setPositiveListener(View.OnClickListener mPositiveListener) {
        this.mPositiveListener = mPositiveListener;
    }
}
